1
/**************************** Module Header ********************************\
2 * Module Name: IPConvert.cs
3 * Project: CSASPNETIPtoLocation
4 * Copyright (c) Microsoft Corporation
6 * This project illustrates how to get the geographical location from a db file.
7 * You need install Sqlserver Express for run the web applicaiton. The code-sample
8 * only support Internet Protocol version 4.
10 * This class use to calculate the IP number from IP address.
12 * This source is subject to the Microsoft Public License.
13 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
14 * All other rights reserved.
16 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
17 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
19 \*****************************************************************************/
23 using System
.Collections
.Generic
;
28 namespace CSASPNETIPtoLocation
30 public class IPConvert
32 public static string ConvertToIPRange(string ipAddress
)
36 string[] ipArray
= ipAddress
.Split('.');
37 int number
= ipArray
.Length
;
41 return "error ipAddress";
43 for (int i
= 0; i
< 4; i
++)
45 int numPosition
= int.Parse(ipArray
[3 - i
].ToString());
48 ipRange
+= numPosition
;
52 ipRange
+= ((numPosition
% 256) * (Math
.Pow(256, (i
))));
55 return ipRange
.ToString();